package com.huizluo.module2.array;

public class PrintArray {
    public static int[][] arr = new int[][]{
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
            {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
    };
    //打印所有元素之和
    private void printSum(){
        System.out.println("-------计算所有数之和--------");
        int sum = 0;
        for (int i = 0;i<16;i++){
            for (int j = 0;j<16;j++){
                sum += PrintArray.arr[i][j];

            }
        }
        System.out.printf("总和是：%d\n",sum);
    }
    //打印左上角到右下角元素之和
    private void leftToRightBottom(){
        int sum = 0;
        System.out.println("-------左上到右下累加-------");
        for (int i = 0;i<16;i++){
            int j = i;
            sum += PrintArray.arr[i][j];
            System.out.printf("➕ [%d,%d] sum = %d\n",i,j,sum);
        }

    }
    //打印右上角到左下角到所有元素之和
    private void rightToLeftBottom(){
        System.out.println("------右上到左下累加-------");
        int sum = 0;
        for (int j = 15;j>=0;j--){
            int i = 15 - j;
            sum += PrintArray.arr[i][j];
            System.out.printf("➕ [%d,%d] sum = %d\n",i,j,sum);
        }
    }

    public static void main(String[] args) {
        PrintArray p = new PrintArray();

        p.printSum();
        p.leftToRightBottom();
        p.rightToLeftBottom();
    }
}
